package com.zone.vehicle.superApps.view.setting;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zone.vehicle.superApps.R;
import com.zone.vehicle.superApps.databinding.FragmentSettingBinding;
import com.zone.vehicle.superApps.view.common.base.BaseFragment;
import com.zone.vehicle.superApps.view.common.listener.ActionListener;
import com.zone.vehicle.superApps.view.setting.widget.CustomDialog;

import org.jetbrains.annotations.NotNull;

public class SettingFragment extends BaseFragment implements View.OnClickListener {

    private static final String TAG = SettingFragment.class.getSimpleName();

    private FragmentSettingBinding binding;
    private CustomDialog dialog;
    private ActionListener listener;

    public SettingFragment(ActionListener listener){
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentSettingBinding.inflate(inflater);
        init();
        return binding.getRoot();
    }

    private void init(){
        addListener(listener);
        binding.item1.setOnClickListener(this);
        binding.item2.setOnClickListener(this);
        binding.item3.setOnClickListener(this);
        binding.item4.setOnClickListener(this);
        binding.btnBack.setOnClickListener(this);
        initDialog();
    }

    private void initDialog(){
        dialog = new CustomDialog(getContext());
        dialog.setTitle("发现新版本");
        dialog.setSubTitle("V 1.0.1");
        dialog.setMessage("更新内容：\n 1.提示消息提示消息提示\n 2.消息提示消息提示消息提示\n 3.消息提示消息提示消息");
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                dialog.cancel();
            }
        });
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.item1:
                showUpdateDialog();
                break;
            case R.id.item2:

                break;
            case R.id.item3:

                break;
            case R.id.item4:
                changePage(SuggestionFragment.class.getSimpleName());
                break;
            case R.id.btn_back:

                break;
        }
    }

    private void showUpdateDialog(){
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }
}